﻿using A.M.ETO;
using AutoMapper;
using DotNetCore.CAP;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using MiniExcelLibs;
using Q.M.Finance.Application.IServices;
using Q.M.Finance.Application.Services;
using Q.M.Finance.Domain.DTO;
using Q.M.Finance.Domain.Entity;
using Q.M.Finance.Infrastruecure.Repository;
using System.Linq.Expressions;

namespace Q.M.Finance.Write.API.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class To_ticket_managementWriteController : ControllerBase
    {
        private readonly ITo_ticket_managementServices to_Ticket_ManagementServices;
        public To_ticket_managementWriteController(ITo_ticket_managementServices to_Ticket_ManagementServices)
        {
            this.to_Ticket_ManagementServices = to_Ticket_ManagementServices;
        }
        /// <summary>
        /// 添加到票管理
        /// </summary>
        /// <param name="to_Ticket_ManagementAddDTO"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> GetTo_ticket_managementAddInfo(to_ticket_managementAddDTO to_Ticket_ManagementAddDTO)
        {
            try
            {
                var res = await to_Ticket_ManagementServices.GetTo_ticket_managementAddInfo(to_Ticket_ManagementAddDTO);
                return Ok(res);
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 修改到票管理
        /// </summary>
        /// <param name="to_Ticket_ManagementShowDTO"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<IActionResult> Getbilling_managementUpdateInfo(to_ticket_managementShowDTO to_Ticket_ManagementShowDTO)
        {
            var res = await to_Ticket_ManagementServices.Getbilling_managementUpdateInfo(to_Ticket_ManagementShowDTO);
            return Ok(res);
        }
        /// <summary>
        /// 反填到票管理
        /// </summary>
        /// <param name="to_ticket_managementid"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> Findto_ticket_managementInfo(string? to_ticket_managementid)
        {
            var res = await to_Ticket_ManagementServices.Findto_ticket_managementInfo(to_ticket_managementid);
            return Ok(res);
        }

        /// <summary>
        /// 删除到票管理
        /// </summary>
        /// <param name="to_ticket_managementid"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<IActionResult> Deleteto_ticket_management(string? to_ticket_managementid)
        {
            var res = await to_Ticket_ManagementServices.Deleteto_ticket_management(to_ticket_managementid);
            return Ok(res);
        }
        /// <summary>
        /// 到票显示+分页+查询
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult Getbilling_managementInfo(string? to_ticket_managementid, int pageIndex, int pageSize)
        {
            var res = to_Ticket_ManagementServices.Getbilling_managementInfo(to_ticket_managementid,pageIndex,pageSize);
            return Ok(res);
        }
        /// <summary>
        /// 导出
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult ExportTiExcel()
        {
            var list = to_Ticket_ManagementServices.GetShowInfor();
            var steram = new MemoryStream();
            steram.SaveAs(list);
            steram.Seek(0, SeekOrigin.Begin);
            return new FileStreamResult(steram, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
            {
                FileDownloadName = "到票信息.xlsx"
            };
        }
    }
}
